package com.jci.vsd.adapter.reim;

/**
 * Created by liqing on 18/6/28.
 */

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.jci.vsd.R;
import com.jci.vsd.bean.reim.MyReimDetailBean;
import com.jci.vsd.constant.MySpEdit;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liqing on 18/3/20.
 */
//--已审批 -审批详情 adapter

public class MyReimRecycleAdapter extends RecyclerView.Adapter<MyReimRecycleAdapter.MyViewHolder> {

    private Context context;
    private List<MyReimDetailBean.CostsBean> list;
    private LayoutInflater inflater;
    private List<Bitmap> listBitmap = new ArrayList<>();

    public MyReimRecycleAdapter(Context context, List<MyReimDetailBean.CostsBean> list) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(this.context);
    }

    public void setListBitmap(List<Bitmap> list) {
        this.listBitmap = list;

    }

    public static interface OnItemClickListener {
        //  void OnItemClick(View view, int pos);
        void onPicCLick(View view, int pos);
    }

    //    public static interface OnItemClickListener {
//        void OnItemClick(View view, int pos);
//    }
    public MyReimRecycleAdapter.OnItemClickListener listener;

    public void setOnItemClickListener(MyReimRecycleAdapter.OnItemClickListener listener) {
        this.listener = listener;
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder myViewHolder = null;
        if (myViewHolder == null) {
            myViewHolder = new MyViewHolder(inflater.inflate(R.layout.item_approved_detail_new, parent, false));

        }
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        final MyReimDetailBean.CostsBean bean = list.get(position);
        if (bean != null) {
            holder.tvFee.setText("¥" + bean.getAmount());
            holder.tvName.setText(MySpEdit.getInstance().getRealName());
            holder.tvExpenseType.setText(bean.getName());
            holder.ivFrame.setTag(position);
            holder.tvDate.setText(bean.getDate());
            Glide.with(context)
                    .load(bean.getUrl())
                    .apply(new RequestOptions().placeholder(R.drawable.ic_image).override(20, 20))
                    .into(holder.ivPic);


            holder.ivFrame.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listener != null) {
                        listener.onPicCLick(view, (int) view.getTag());
                    }

                }
            });

        }

    }

    //

    @Override
    public int getItemCount() {

        if (list == null)
            return 0;
        return list.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tvFee;
        TextView tvDate;
        TextView tvName;
        TextView tvExpenseType;
        ImageView ivPic;
        View view;
        FrameLayout ivFrame;

        public MyViewHolder(View view) {
            super(view);
            tvFee = (TextView) view.findViewById(R.id.tv_money);
            tvDate = (TextView) view.findViewById(R.id.tv_expense_time);
            tvName = (TextView) view.findViewById(R.id.tv_title);
            tvExpenseType = (TextView) view.findViewById(R.id.tv_expense_type);
            ivPic = (ImageView) view.findViewById(R.id.iv_expense_item_pic);
            ivFrame = (FrameLayout) view.findViewById(R.id.iv_frame);
            this.view = view;
        }
    }
}
